package cn.ryh.eurekaorder.consumer.controller;
import cn.ryh.apicommons.entities.CommonResult;
import cn.ryh.apicommons.entities.Payment;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @ClassName PaymentController
 * @Description TODO
 * @Author RaoYH
 * @CreateDate 2020/11/20
 * @UpdateUser RaoYH
 * @UpdateDate 2020/11/20
 * @UpdateRemark TODO
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/consumer")
public class ConsumerController {
    @Resource
    private RestTemplate restTemplate;
    // private static final String PAYMENT_URL="http://localhost:8001";
    /**
     * 单机版直接url地址和端口
     * 集群版写微服务名称
     */
    private static final String PAYMENT_URL="http://CLOUD-PAYMENT-SERVICE";
    @PostMapping(value = "/create")
    public CommonResult create(Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "/payment/create", payment, CommonResult.class);
    }
    /**
     * 对应访问url /payment/get/=1
     */
    @GetMapping(value = "/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id) {
        return restTemplate.getForObject(PAYMENT_URL+"/payment/get/"+id,CommonResult.class);
    }

}
